package web.reader;

import java.util.ArrayList;

/**
 * An HTML element is everything from the start tag to the end tag 
 * The start tag is often called the opening tag. The end tag is often called 
 * the closing tag.
 * 
 * HTML Element Syntax: 
 *   An HTML element starts with a start tag / opening tag
 *   An HTML element ends with an end tag / closing tag
 *   The element content is everything between the start and the end tag
 *   Some HTML elements have empty content
 *   Empty elements are closed in the start tag
 *   Most HTML elements can have ATTRIBUTES
 * 
 * @author Shimu
 * @date 16-Sep-2012
 */
public class HtmlElement {

    public final String TYPE_PARAGRAPH = "p";
    public final String TYPE_LINK = "link";
    public final String TYPE_HYPERLINK = "a";
    
    private final ArrayList<HtmlAttribute> ATTRIBUTES;

    private final String NAME;

    private final String CONTENT;

    public HtmlElement(String name) {
        this(name, "");
    }

    public HtmlElement(String name, String content) {
        this(name, content, new ArrayList<HtmlAttribute>());
    }

    public HtmlElement(String name, ArrayList<HtmlAttribute> attributes) {
        this(name, "", attributes);
    }

    public HtmlElement(String name, String content,
            ArrayList<HtmlAttribute> attributes) {
        this.ATTRIBUTES = attributes;
        this.NAME = name;
        this.CONTENT = content;
    }

    /**
     * Returns the name of the element (the string inside the
     * start/opening tag).
     * 
     * @return 
     */
    public String getName() {
        return NAME;
    }

    /**
     * Returns a list of attributes of this html element. The
     * list may be empty if now attributes are found.
     * 
     * @return 
     */
    public ArrayList<HtmlAttribute> getAttributes() {
        return ATTRIBUTES;
    }

    /**
     * Returns the content of the element (everything between
     * the start and end tag)
     * 
     * @return
     */
    public String getContent() {
        return CONTENT;
    }
    
    @Override
    public String toString() {
        return "Html Element: "  + NAME + ", " + CONTENT + ", " + ATTRIBUTES;         
    }
}
